package cn.wk.dao.impl;

import cn.wk.dao.AdminsDao;
import cn.wk.dao.TeacherDao;
import cn.wk.entity.Admins;
import cn.wk.entity.Teacher;
import cn.wk.util.JDBCUtil;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class TeacherDaolmpl implements TeacherDao {
    private JdbcTemplate template=new JdbcTemplate(JDBCUtil.getDataSource());
    @Override
    public List<Teacher> getAllTeacher(Object...obj) {
        String sql="select * from teacher limit ?,?";
        List<Teacher> list=  template.query(sql, new BeanPropertyRowMapper<>(Teacher.class),obj);
        return list;
    }
    @Override
    public int  CountSize(){
        String sql="select count(*) from teacher";
        int b=template.queryForObject(sql,Integer.class);
        return b;
    }

    @Override
    public int AddTeacher(Object... obj) {
        String sql="insert teacher values(null,?,?,?,?,?,?,?,?)";
        int b=template.update(sql,obj);
        return b;
    }

    @Override
    public int MidffTeacher(Object... obj) {
        String sql="update teacher set tpwd=?,tname=?,tgender=?,taddress=?,ttel=?,temail=?,status=? where tid=?";
        int b=template.update(sql,obj);
        return b;
    }

    @Override
    public int DelTeacher(Object... obj) {
       return 0;
    }



    @Override
    public Teacher findTeacherById(int tid) {
        String sql="select * from teacher where tid=?";
      Teacher teacher=  template.queryForObject(sql,new BeanPropertyRowMapper<>(Teacher.class),tid);
        return teacher;
    }

    @Override
    public Teacher findTeacherByNo(String no) {
        String sql="select * from teacher where tno=?";
        Teacher teacher=  template.queryForObject(sql,new BeanPropertyRowMapper<>(Teacher.class),no);
        return teacher;
    }

    @Override
    public List<Teacher> getByTeacherNameandId() {
        String sql="select tid,tname from teacher";
        List<Teacher> list=  template.query(sql, new BeanPropertyRowMapper<>(Teacher.class));
        return list;
    }


}
